########################################
## admin.py
## 
## Contains administration commands
##
## History:
##   pireau   2007-09-15      Code entry
##

import irc_protocol
import authenticate

def link(commands, help):
    help["nick"] = ["changes the bot's nick",
                    ["send: !nick <new nick> to the bot in private"]
                   ]
    help["join"] = [ "joins the specified channel",
                     ["send: !join <channel> to join another channel"]
                   ]
    help["part"] = [ "leaves the specified channel", 
                     ["send: !part <channel> to leave the channel"]
                   ] 

    commands["nick"] = process_command
    commands["join"] = process_command
    commands["part"] = process_command

###########################################
##
## Checks if the user is allowed the admin
##
def user_is_admin( command, authenticate):
    if authenticate.user_level(command[0]) >= 90:
        return True
    else:
        return False

###########################################
##
## Checks if the user is the admin and
## takes the appropriate action.
##
def process_command( server, command, help, authenticate ):
        
    if user_is_admin(command,authenticate):
        command_line = command[3].split(' ')
        if len(command_line) == 1:
            server.send(
                        irc_protocol.reply_private( command, help[ command_line[0][1:] ][1][0] ))
        else:
            server.send(command[3][1:])
    else:
        server.send(
                irc_protocol.reply_private(
                                command, "insufficient access level." ))
